package com.srit.yoggsaron.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "测试接口")
@RestController
@RequestMapping(value = "/serviceInfo")
@PropertySource(value="classpath:application.properties" , encoding = "UTF-8")
public class TestController {
	private final Logger logger = LoggerFactory.getLogger(TestController.class);
	 
	
	

	@ApiOperation(value = "测试服务是否正常的接口", httpMethod = "GET", notes = "测试服务是否正常")
	@GetMapping(value = "/serviceInfo")
	@ResponseBody
	public Object serviceInfo(HttpServletRequest request, HttpServletResponse response) {
		logger.debug("==================================");
		logger.debug("Port={}", request.getLocalPort());
		logger.debug("RequestURI={}", request.getRequestURI());
		Map<String, String[]> parameterMap = request.getParameterMap();
		Iterator<String> iter = parameterMap.keySet().iterator();

		logger.debug("测试服务是否正常");

		logger.debug("parameters:");
		while (iter.hasNext()) {
			String key = iter.next();
			String[] values = parameterMap.get(key);
			logger.debug("parameter name = {} ,value = {}", key, values);
		}
		Map<String, Object> responseBodyMap = new HashMap<String, Object>();
		responseBodyMap.put("requestTime", new Date());
		responseBodyMap.put("result", "OK");
		responseBodyMap.put("message", "Service is OK!");
		logger.debug("==================================");
		return responseBodyMap;
	}

}
